// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Music, {musicName} from "../PublicScript/Music";
import GameData_red_blue_man from "./GameData_red_blue_man";
import PowerControl from "../PublicScript/PowerControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Setting extends cc.Component {

    @property({tooltip: "音乐按钮", type: cc.Node})
    musBtn: cc.Node = null;
    @property({tooltip: "音效按钮", type: cc.Node})
    effectBtn: cc.Node = null;
    @property({tooltip: "震动按钮", type: cc.Node})
    shackBtn: cc.Node = null;
    @property(cc.Node)
    otherNode: cc.Node = null;

    //状态
    // static musState = true;
    // static effectState = true;
    // static shackState = true;

    onLoad () {
        this.init();
    }

    start () {

    }

    init(){
        this.musBtn.children[0].active = GameData_red_blue_man.settingState.music;
        this.effectBtn.children[0].active = GameData_red_blue_man.settingState.effect;
        this.shackBtn.children[0].active = GameData_red_blue_man.settingState.shake;
        this.otherNode.active = cc.director.getScene().name != "Welcome";
    }

    onClick(e, d){
        let index = parseInt(d);
        Music.GamePlayEffect(musicName.click);
        //音乐
        if(index == 1){
            this.musBtn.children[0].active = !this.musBtn.children[0].active;
            GameData_red_blue_man.settingState.music = !GameData_red_blue_man.settingState.music;
            if(GameData_red_blue_man.initMusic){
                GameData_red_blue_man.initMusic = false;
                Music.playBgm(musicName.bgm);
            }else{
                Music.gameMusicControl(GameData_red_blue_man.settingState.music);
            }

            GameData_red_blue_man.saveSettingState();
        }
        //音效
        if(index == 2){
            this.effectBtn.children[0].active = !this.effectBtn.children[0].active;
            if(GameData_red_blue_man.settingState.effect){
                cc.audioEngine.stopAllEffects();
            }
            GameData_red_blue_man.settingState.effect = !GameData_red_blue_man.settingState.effect;
            GameData_red_blue_man.saveSettingState();
        }
        //震动
        if(index == 3){
            this.shackBtn.children[0].active = !this.shackBtn.children[0].active;
            GameData_red_blue_man.settingState.shake = !GameData_red_blue_man.settingState.shake;
            GameData_red_blue_man.saveSettingState();
        }
        // //重来
        // if(index == 4){
        //     PowerControl.reducePower(()=>{
        //         cc.director.loadScene("GameScene");
        //     })
        // }
        // //重来
        // if(index == 5){
        //     GameData.showVideo({callback: ()=>{
        //             GameData.nextGame(1);
        //         }, name: "设置界面跳关"})
        // }
    }

    //震动
    static shake(type){
        if(!GameData_red_blue_man.settingState.shake){
            return;
        }
        if(type == 1){  //短
            
        }
        if(type == 2){  //长
            
        }
    }

    // update (dt) {}
}
